<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta http-equiv="Cache-Control" content="no-siteapp">
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=1, minimum-scale=1, maximum-scale=1">
<meta name="renderer" content="webkit">
<meta name="google" value="notranslate">
<meta name="robots" content="index,follow">


<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Akkuman">
<meta name="twitter:description" content="Akkuman的技术博客">
<meta name="twitter:image:src" content="http://127.0.0.1:8000/images/avatar.png">

<meta property="og:url" content="http://127.0.0.1:8000">
<meta property="og:title" content="Akkuman">
<meta property="og:description" content="Akkuman的技术博客">
<meta property="og:site_name" content="Akkuman">
<meta property="og:image" content="http://127.0.0.1:8000/images/avatar.png">
<meta property="og:type" content="website">
<meta name="robots" content="noodp">

<meta itemprop="name" content="Akkuman">
<meta itemprop="description" content="Akkuman的技术博客">
<meta itemprop="image" content="http://127.0.0.1:8000/images/avatar.png">

<link rel="canonical" href="http://127.0.0.1:8000">

<link rel="shortcut icon" href="/favicon.png">
<link rel="apple-itouch-icon" href="/favicon.png">

<link type="text/css" rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/4.0.0/css/bootstrap.min.css">
<link type="text/css" rel="stylesheet" href="/bundle/css/prism.css">
<link type="text/css" rel="stylesheet" href="/bundle/css/zoom.css">
<link type="text/css" rel="stylesheet" href="/bundle/css/main.css">
<script src="https://cdn.bootcss.com/jquery/2.2.4/jquery.min.js"></script>



<script>var cPlayers = [];var cPlayerOptions = [];</script>


<script type="text/javascript">
    var timeSinceLang = {
        year: '年前',
        month: '个月前',
        day: '天前',
        hour: '小时前',
        minute: '分钟前',
        second: '秒前'
    };
    var root = '';
</script>


        <meta name="keywords" content="Golang,Tools,">
        <meta name="description" content="Golang初练手-多线程网站路径爆破">
        <meta name="author" content="Akkuman">
        <title>Golang初练手-多线程网站路径爆破</title>
    </head>
    <body>
        
        <header id="header" class="clearfix">
  <div class="container-fluid">
      <div class="row">
          <div class="logo">
              <div class="header-logo">
                <script>
                  var getwbclass = function() {
                    var wbclass = ['b', 'w'];
                    return wbclass[Math.floor(Math.random()*wbclass.length)];
                  }
                  var sitetitle = "Akkuman";
                  for (i in sitetitle) {
                    document.write('<a href="/"><span class="' + getwbclass() + ' titlechar">' + sitetitle.charAt(i) + '</span></a>');
                  }          
                  
                </script>
                
                <a id="btn-menu" href="javascript:isMenu();">
                    <span class="b">·</span>
                </a>
                <a href="javascript:isMenu1();">
                    <span id="menu-1" class="bf">1</span>
                </a>
                <a href="javascript:isMenu2();">
                    <span id="menu-2" class="bf">2</span>
                </a>
                <a href="javascript:isMenu3();">
                    <span id="menu-3" class="bf">3</span>
                </a>
              </div>
              <div id="menu-page">
                <a href="/archive.html"><li>归档</li></a>
                <a href="/tag.html"><li>标签</li></a>
                
                <a href="/atom.xml"><li>订阅</li></a>
                
                <a href="about.html"><li>关于</li></a>
              </div>
              <div id="search-box">
                  <div id="search">
                      <input autocomplete="off" type="text" name="s" id="menu-search" placeholder="搜索..." data-root="" />
                  </div>
              </div>
          </div>
      </div>
  </div>
  </header>
        <div id="body" class="clearfix">
            <div class="container-fluid">
                <div class="row">
                    <div id="main" class="col-12 clearfix" role="main">
                        <article class="posti" itemscope itemtype="http://schema.org/BlogPosting">
                            <h1 class="post-title" itemprop="name headline">Golang初练手-多线程网站路径爆破</h1>
                            <div class="post-meta">
                                <p>
                                    Written by <a itemprop="name" href="/about.me.html" rel="author">Akkuman</a> with ♥ on <time datetime="1486488348" itemprop="datePublished"></time> in <a href="/tag/Golang/index.html">Golang </a><a href="/tag/Tools/index.html">Tools </a>
                                </p>
                            </div>
                            <div class="post-content" itemprop="articleBody">
                                <p>以前用Python写过这个工具，前两天看了golang的基础，就想着用这个语言把这个工具重写一遍</p>

<p>先放张图<img src="" data-src="https://ooo.0o0.ooo/2017/03/04/58ba4e8c66d38.gif" alt="演示1.gif" /></p>

<p>用法</p>

<pre><code>    Example : Buster.exe -u=https://www.baidu.com -d=asp.txt -t=5
    Buster是你的程序名字
    -u后面填网址参数，格式如上
    -d选字典
    -t是线程数
    当你第一次运行请直接在命令行运行你的程序，什么参数都别加，他会有提示信息告诉你怎么做的
</code></pre>

<p>话不多说，直接上代码，字典采用的以前搜集的一个珍藏的大字典，跑起来可能耗时比较久，文件外链会放在底下</p>

<pre><code class="language-Golang">package main

import (
	&quot;bufio&quot;
	&quot;flag&quot;
	&quot;fmt&quot;
	&quot;io/ioutil&quot;
	&quot;net/http&quot;
	&quot;os&quot;
	&quot;sync&quot;
)

var urls chan string
var no404URL = make(chan string)
var wg sync.WaitGroup //等待goroutine完成

func main() {

	var baseURL string
	var dicPath string
	var threadCount int
	flag.StringVar(&amp;baseURL, &quot;u&quot;, &quot;https://www.baidu.com&quot;, &quot;website which you want to burst&quot;)
	flag.StringVar(&amp;dicPath, &quot;d&quot;, &quot;asp.txt&quot;, &quot;dic which you want to use&quot;)
	flag.IntVar(&amp;threadCount, &quot;t&quot;, 5, &quot;number of Thread&quot;)
	flag.Parse()

	if len(os.Args) == 1 {
		fmt.Println(&quot;------------------------------------&quot;)
		fmt.Println(&quot; Author      |       Akkuamn&quot;)
		fmt.Println(&quot;------------------------------------&quot;)
		fmt.Println(&quot; Update-v1.0 |      2017-02-07&quot;)
		fmt.Println(&quot;-------------------------------------&quot;)
		fmt.Printf(&quot;\nUsage : \n\tExample : %s -u=https://www.baidu.com -d=asp.txt -t=5\n\n&quot;, os.Args[0])
		fmt.Printf(&quot;View more help via %s -h\n\n&quot;, os.Args[0])
		listDic(&quot;dic&quot;)
	} else {
		dicPath = &quot;./dic/&quot; + dicPath
		start(baseURL, dicPath, threadCount)
		wg.Wait() //等待goroutine完成
	}
}

func start(baseURL string, dicPath string, threadCount int) {

	dicFile, dicError := os.OpenFile(dicPath, os.O_RDONLY, 0)
	if dicError != nil {
		fmt.Printf(&quot;\nOpenFile Error:文件打开出错，请检查字典文件是否存在，或文件名是否准确\n&quot;)
		return
	}
	defer dicFile.Close()

	//把处理后的需要爆破的url全部传到信道urls
	ReturnBurstURL(dicFile, baseURL)

	//单独开goroutine从信道no404URL取数据写入文件
	go func() {
		resultTxt, err := os.OpenFile(&quot;result.txt&quot;, os.O_CREATE|os.O_TRUNC|os.O_RDWR, 0660)
		if err != nil {
			fmt.Println(&quot;OpenFile Error:&quot; + err.Error())
		}
		resultWriter := bufio.NewWriter(resultTxt)
		defer resultTxt.Close()
		for {
			_, err = resultWriter.WriteString(&lt;-no404URL)
			if err != nil {
				fmt.Println(&quot;resultWriter Error:&quot; + err.Error())
			}
			resultWriter.Flush()
		}
	}()

	//并发访问网址并将状态码不为404的网址加入信道no404URL
	for i := 0; i &lt; threadCount; i++ {
		wg.Add(1)
		go func(i int) {
			for len(urls) &gt; 0 {
				url := &lt;-urls
				status := HTTPStatus(url)
				fmt.Printf(&quot;[%d]%s-----%s\n&quot;, i, status, url)
				if status != &quot;404 Not Found&quot; {
					no404URL &lt;- status + &quot;-----&quot; + url + &quot;\n&quot;
				}
			}
			wg.Done()
		}(i)
	}
}

//返回HTTP访问状态码
func HTTPStatus(url string) (status string) {
	client := http.DefaultClient
	reqest, err := http.NewRequest(&quot;HEAD&quot;, url, nil)
	if err == nil {
		reqest.Header.Set(&quot;User-Agent&quot;, &quot;Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:51.0) Gecko/20100101 Firefox/51.0&quot;)
		reqest.Header.Set(&quot;Accept&quot;, &quot;text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8&quot;)
		response, err1 := client.Do(reqest)
		if err1 != nil {
			fmt.Println(&quot;HTTPRequest Error:&quot; + err1.Error())
		}

		defer response.Body.Close()
		return response.Status
	} else {
		fmt.Println(&quot;NewRequest Error:&quot; + err.Error())
		return &quot;400 Bad Request&quot;
	}
}

//把处理后的需要爆破的url全部传到信道urls
func ReturnBurstURL(fURL *os.File, baseurl string) {
	var urlList []string
	allURLTxt := bufio.NewScanner(fURL)
	for allURLTxt.Scan() {
		newurl := baseurl + &quot;/&quot; + allURLTxt.Text()
		urlList = append(urlList, newurl)
	}
	urls = make(chan string, len(urlList))
	for _, url := range urlList {
		urls &lt;- url
	}
	fmt.Printf(&quot;\n读取字典完成，准备开始，请等待...\n&quot;)
}

//罗列出可用字典
func listDic(dicDir string) {
	dirList, err := ioutil.ReadDir(dicDir)
	if err != nil {
		fmt.Println(&quot;ReadDir Error : &quot; + err.Error() + &quot;\n&quot;)
	}
	fmt.Println(&quot;Dic you can select : &quot;)
	for _, file := range dirList {
		fmt.Printf(&quot;    %s\n&quot;, file.Name())
	}
}
</code></pre>

<p>只编译了win平台下的，如果有需要可以自行编译</p>

<p><strong><a href="http://pan.baidu.com/s/1c2BYT8k">源码及字典及win程序</a></strong>
<strong>密码: g1gd</strong></p>

                            </div>
                            <div style="display:block;" class="clearfix">
                                <section style="float:left;">
                                    <span itemprop="keywords" class="tags">
                                        tag(s): <a href="/tag/Golang/index.html">Golang </a><a href="/tag/Tools/index.html">Tools </a>
                                    </span>
                                </section>
                                <section style="float:right;">
                                    <span><a id="btn-comments" href="javascript:isComments();">show comments</a></span> · <span><a href="javascript:goBack();">back</a></span> · 
                                    <span><a href="/">home</a></span>
                                </section>
                            </div>
                            



<div id="comments" class="gen">
    <script>
        document.write('<section id="disqus_thread"></section>');
        var site_comment_load = function disqus() {
            var d = document, s = d.createElement('script');
            s.src = '//Akkum4n.disqus.com/embed.js';
            s.setAttribute('data-timestamp', +new Date());
            (d.head || d.body).appendChild(s);
        }
    </script>
</div>

                        </article>
                    </div>
                </div>
            </div>
        </div>
        <footer id="footer" role="contentinfo">
    <div class="container-fluid">
        <div class="row">
        <div class="col-12">
            &copy; 
            <script type="text/javascript">
                document.write(new Date().getFullYear());
            </script>
            <a href="/">Akkuman</a>.
            Using <a target="_blank" href="http://www.chole.io/">Ink</a> & <a target="_blank" href="/">Story</a>.
        </div>
        </div>
    </div>
</footer>

<script src="https://cdn.bootcss.com/jquery/2.2.4/jquery.min.js"></script>
<script src="/bundle/js/prism.js"></script>
<script src="/bundle/js/zoom-vanilla.min.js"></script>
<script src="/bundle/js/main.js"></script>

<script>
    window.onload=function(){
        if (window.location.hash!='') {
          var i=window.location.hash.indexOf('#comment');
          var ii=window.location.hash.indexOf('#respond-post');
          if (i != '-1' || ii != '-1') {
            document.getElementById('btn-comments').innerText='hide comments';
            document.getElementById('comments').style.display='block';
          }
        }
    }

    function isMenu(){
        if(document.getElementById('menu-1').style.display=='inline'||document.getElementById('menu-1').style.display=='block'){
            $('#search-box').fadeOut(200);
            $('#menu-page').fadeOut(200);
            $('#menu-1').fadeOut(500);
            $('#menu-2').fadeOut(400);
            $('#menu-3').fadeOut(300);
        } else {
            $('#menu-1').fadeIn(150);
            $('#menu-2').fadeIn(150);
            $('#menu-3').fadeIn(150);
        }
    }

    function isMenu1(){
        if(document.getElementById('menu-page').style.display=='block'){
            $('#menu-page').fadeOut(300);
        } else {
            $('#menu-page').fadeIn(300);
        }
    }

    function isMenu2(){
        if(document.getElementById('torTree')){
            if(document.getElementById('torTree').style.display=='block'){
                $('#torTree').fadeOut(300);
            } else {
                $('#torTree').fadeIn(300);
            }
        }
    }

    function isMenu3(){
        if(document.getElementById('search-box').style.display=='block'){
            $('#search-box').fadeOut(300);
        } else {
            $('#search-box').fadeIn(300);
        }
    }

    function isComments(){
        if(document.getElementById('btn-comments').innerText=='show comments'){
            document.getElementById('btn-comments').innerText='hide comments';
            document.getElementById('comments').style.display='block';
            site_comment_load();
        } else {
            document.getElementById('btn-comments').innerText='show comments';
            document.getElementById('comments').style.display='none';
        }
    }

    function Search404(){
        $('#menu-1').fadeIn(150);
        $('#menu-2').fadeIn(150);
        $('#menu-3').fadeIn(150);
        $('#search-box').fadeIn(300);
    }

    function goBack(){
        window.history.back();
    }
</script>


<script async>
"use strict";
(function(){
var cp = function(){
    var len = cPlayerOptions.length;
    for(var i=0;i<len;i++){
        var element = document.getElementById('player' + cPlayerOptions[i]['id'])
        while (element.hasChildNodes()) {
            element.removeChild(element.firstChild);
        };
        cPlayers[i] = new cPlayer({
            element: element,
            list: cPlayerOptions[i]['list'],
            });
    };
    cPlayers = [];cPlayerOptions = [];
};
var script = document.createElement('script');
script.type = "text/javascript";
script.src = "https://cdn.bootcss.com/cplayer/3.2.1/cplayer.js";
script.async = true;
if(script.readyState){  
    script.onreadystatechange = function(){
        if (script.readyState == "loaded" ||
            script.readyState == "complete"){
            script.onreadystatechange = null;
            cp();
        }
    };
}else{  
    script.onload = function(){
        cp();
    };
}
document.head.appendChild(script);
})();
</script>

    </body>
</html>
